<template>
  <div class="app-container">
    <el-card>
      <el-tabs>
        <el-tab-pane label="账号设置">
          <el-form ref="userForm" :model="userInfo" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
            <el-form-item prop="username" label="用户名">
              <input v-model="userInfo.username" type="text" style="width:300px">
            </el-form-item>
            <el-form-item prop="password" label="密码">
              <input
                v-model="userInfo.password"
                type="password"
                style="width:300px"
              >
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="btnOk">更新</el-button>
            </el-form-item>

          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情"><UserInfo /></el-tab-pane>
        <el-tab-pane label="岗位信息"><JobInfo /></el-tab-pane>

      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getUserDetailById } from '@/api/user'
import { saveUserInfoById } from '@/api/employees'
import JobInfo from './component/job-info.vue'
import UserInfo from './component/user-info.vue'
export default {
  components: {
    JobInfo,
    UserInfo

  },
  data() {
    return {
      userId: this.$route.params.id,
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '输入不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '输入不能为空', trigger: 'blur' }
        ]

      }
    }
  },
  async created() {
    console.log('用户信息', this.userId)
    const res = await getUserDetailById(this.userId)
    console.log(res)
    this.userInfo = res.data
    this.userInfo.password = ''
  },
  methods: {
    async btnOk() {
      await this.$refs.userForm.validate()
      await saveUserInfoById(this.userInfo)
      this.$message.success('修改成功')
    }
  }

}
</script>

<style>

</style>
